package com.wink_172.library.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

import com.wink_172.library.R;
import com.wink_172.library.model.Constants;
import com.wink_172.library.utils.DisplayUtil;

import java.util.HashSet;

public
/**
 最精简的圆环进度条控件
 不参与任何业务计算
 * 只是作为单独的组件绘制某一时刻进度 不参与倒计时
 * */

 class CustomCircleView extends View {
    //圆轮颜色
    public int mRingColor;
    //圆轮非完成颜色
    public int mRingColor2;
    //圆轮宽度
    public  float mRingWidth;
    //宽度
    public  int mWidth;
    //高度
    public  int mHeight;
    public  Paint mPaint;
    //圆环的矩形区域
    public RectF mRectF;
    public  float mCurrentAngle;//为360度的角百分比



    public CustomCircleView(Context context) {
        this(context, null);
    }

    public CustomCircleView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CustomCircleView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mRingColor = context.getResources().getColor( R.color.logcat_level_info_color);
        mRingColor2 = context.getResources().getColor( R.color.logcat_level_verbose_color);
        mRingWidth = 3;

        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mPaint.setAntiAlias(true);

        this.setWillNotDraw(false);
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
        mWidth = getMeasuredWidth();
        mHeight = getMeasuredHeight();
        mRectF = new RectF(0 + mRingWidth / 2, 0 + mRingWidth / 2,
                mWidth - mRingWidth / 2, mHeight - mRingWidth / 2);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        //颜色
        mPaint.setColor(mRingColor);
        //空心
        mPaint.setStyle(Paint.Style.STROKE);
        //宽度
        mPaint.setStrokeWidth(mRingWidth);


        //绘制一圈未完成圆环
        mPaint.setColor(mRingColor2);
        canvas.drawArc(mRectF, 0,   360, false, mPaint);//圆形

        //颜色
        mPaint.setColor(mRingColor);

        //已完成圆环
        canvas.drawArc(mRectF, -90,   360-mCurrentAngle, false, mPaint);//圆形





    }

    private static final String TAG = "CustomCircleView";


    /**
     * 只是作为单独的组件绘制某一时刻进度 不参与倒计时
     * current 为360度的百分比
     * */
    public void onlyUpdate(Float current){
        mCurrentAngle=current;
        invalidate();
    }
}